package com.shanzmoo.h5.domain.req;

import com.shanzmoo.base.constant.PayStatusConstant;
import com.shanzmoo.base.constant.e.PayTypeEnum;
import com.shanzmoo.base.constant.e.WxTradeTypeEnum;
import com.shanzmoo.base.util.BillNoUtils;
import com.shanzmoo.db.trade.entity.PayOrderEntity;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import java.io.Serializable;

/**
 * 获取支付二维码请求信息
 *
 * @author Gzhao
 * @date 2020/12/6
 */
@Data
@ApiModel("获取支付二维码请求信息")
public class PayOrderQrCodeReq implements Serializable {

    private static final long serialVersionUID = 1758L;

    @NotNull
    @ApiModelProperty(value = "支付类型", example = "Wx")
    private PayTypeEnum payType;

    @NotBlank
    @ApiModelProperty(value = "订单号", example = "MA202012102353489219")
    private String orderNo;

    @NotBlank
    @ApiModelProperty(value = "订单(商品)描述", example = "测试订单")
    private String describe;

    @NotNull
    @ApiModelProperty(value = "标价金额(分)", example = "1")
    private Integer totalFee;

    @NotBlank
    @ApiModelProperty(value = "用户IP", example = "123.12.12.123")
    private String ip;

    @ApiModelProperty(value = "交易类型(微信)", example = "NATIVE")
    private WxTradeTypeEnum tradeType;

    /**
     * (微信)商品ID, trade_type=NATIVE时，此参数必传
     */
    @ApiModelProperty(value = "商品ID", example = "100021")
    private String productId;

    public PayOrderEntity convertToPayOrderEntity() {
        String feeType = payType == PayTypeEnum.Wx ? "CNY" : "";
        return PayOrderEntity.builder()
                .type(payType.getCode())
                .payNo(BillNoUtils.generatePayNo())
                .orderNo(orderNo)
                .payStatus(PayStatusConstant.WAIT_PAY)
                .body(describe)
                .feeType(feeType)
                .totalFee(totalFee)
                .ip(ip)
                .tradeType(tradeType.getDesc())
                .productId(productId)
                .build();

    }

}
